import { useFormLabelWidth } from "element-plus/es/components/form/src/utils";
import { createRouter, createWebHashHistory, RouteLocationNormalized, RouteRecordRaw } from "vue-router";
import { Menu } from "../api/entity/Menu";
import { AddRouter, getMenu } from "../api/menuApi";

export const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/login',
        meta:{
            hidden:true
        }
        
    },
    {
        path: '/home',
        name: 'web',
        component: () => import("../view/web/home.vue"),
        meta:{
            hidden:true
        }

    },
    {
        path: '/admin/home',
        name: 'home',
        component: () => import("../view/admin/home.vue"),
        meta:{
            hidden:true
        }
    },
    {
        path: '/login',
        name: 'login',
        meta: {
          hidden:true
        },
        component: () => import("../view/login.vue")
    }
]
const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach(async (to, from, next) => {
    if (to.name !== 'Login' &&localStorage.getItem("token")){
         await AddRouter()
          next()
    }
    else{
        next({ name: 'Login' })
    } 
  })
  



export default router;

